#include<iostream>
#include<cstring>
using namespace std;

const int N = 1010;
int v[N] , w[N];
int dp[N][N];
int n , V;
int main()
{
    cin >> n >> V;
    for(int i = 1;i <= n;i ++) cin >> v[i] >> w[i];
    for(int i = 1;i <= n;i ++)
    {
        for(int j = 0;j <= V;j++)
        {
            dp[i][j] = dp[i-1][j];
            if(v[i] <= j) dp[i][j] = max(dp[i][j] , dp[i-1][j-v[i]] +w[i]);
        }
    }
    cout << dp[n][V] << endl;
    memset(dp , -0x3f3f3f3f , sizeof dp);
    dp[0][0] = 0;
    for(int i = 1;i <= n;i ++)
    {
        for(int j = 0;j <= V;j++)
        {
            dp[i][j] = dp[i-1][j];
            if(v[i] <= j) dp[i][j] = max(dp[i][j] , dp[i-1][j-v[i]] +w[i]);
        }
    }
    if(dp[n][V] < 0) cout << 0 << endl;
    else cout << dp[n][V] << endl;
    return 0;
}